<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('新增盘点')"/>
<meta charset="UTF-8"/>
<title>Title</title>
<!-- load css -->

<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" media="all"/>
<style>

</style>

<body>
<div class="layui-fluid larry-wrapper">
    <div class="layui-row layui-col-space30">
        <div class="layui-col-xs24">
            <section class="panel panel-padding">
                <form id="form1" class="layui-form layui-form-pane" action="">
                    &nbsp;
                    &nbsp;

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">账户类型</label>
                            <div class="layui-input-inline">
                                <select id="lx" lay-verify="required" lay-filter="lx" data-required="data-required" >
                                    <option value="">请选择</option>
                                    <option value="0">全部账户</option>
                                    <option value="1">当前登陆账户</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">人员</label>
                            <div class="layui-input-inline">
                                <select lay-ignore="lay-ignore" class="zyryid" id="zyryid" name="zyryid"  lay-filter="zyryid" onchange="getName()"  select2   style="width: 193px" ></select>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item" style="float: right;">
                        <div class="layui-input-block">
                            <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addCustomer">立即提交
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                    <input type="hidden" id="zyrymc" name="zyrymc">
                    <input type="hidden" th:value="${id}" id="id" name="id">
                </form>
            </section>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" th:src="@{/plugin/layui/js/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/plugin/layui/js/version.js}"></script>
<script th:src="@{/plugin/layui/js/common.js}"></script>
<div th:include="public/public_js::public_js"></div>
<script>



    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'form'], function () {
        var form = layui.form,
            zzpUtils = layui.zzpUtils,
            laydate = layui.laydate;
        $ = layui.jquery;
        $('#zyryid').select2({
          /*  ajax: {
                url: "/zxsswms/wmsqualityinspectionlist/selectPDADLByHz",
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        name: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    console.info(data);
                    var arr = new Array();
                    if (data) {
                        for (var i = 0; i < data.length; i++) {
                            arr.push({id: data[i].id, text: data[i].name});
                        }
                    }
                    return {
                        results: arr
                    };
                },
                cache: true
            },*/
            language: "zh-CN",
            placeholder: '请输入查询字段',
            allowClear: true
        });

        form.on('select(lx)', function (data) {
            if($("#lx").val()==0){//全部账户
                $('#zyryid').select2({
                    ajax: {
                        url: "/zxsswms/wmsqualityinspectionlist/selectYh",
                        dataType: 'json',
                        type: 'POST',
                        contentType: "application/json",
                        data: function (params) {
                            var query = {
                                name: params.term
                            };
                            return JSON.stringify(query);
                        },
                        processResults: function (data) {
                            console.info(data);
                            var arr = new Array();
                            if (data) {
                                for (var i = 0; i < data.length; i++) {
                                    arr.push({id: data[i].id, text: data[i].name});
                                }
                            }
                            return {
                                results: arr
                            };
                        },
                        cache: true
                    },
                    language: "zh-CN",
                    placeholder: '请输入查询字段',
                    allowClear: true
                });
            }else if($("#lx").val()==1){//当前登陆账户
                $('#zyryid').select2({
                    ajax: {
                        url: "/zxsswms/wmsqualityinspectionlist/selectPDADLByHz",
                        dataType: 'json',
                        type: 'POST',
                        contentType: "application/json",
                        data: function (params) {
                            var query = {
                                name: params.term
                            };
                            return JSON.stringify(query);
                        },
                        processResults: function (data) {
                            console.info(data);
                            var arr = new Array();
                            if (data) {
                                for (var i = 0; i < data.length; i++) {
                                    arr.push({id: data[i].id, text: data[i].name});
                                }
                            }
                            return {
                                results: arr
                            };
                        },
                        cache: true
                    },
                    language: "zh-CN",
                    placeholder: '请输入查询字段',
                    allowClear: true
                });
            }
        })
         window.getName=function(){
            $("#zyrymc").val($("#zyryid").text());

        }

        zzpUtils.select2({
            elem: "#selectId",  //dom
            url: "/wmsCustomerFiles/baseSelectLine" //路径
        });

        form.on("submit(addCustomer)", function (data) {
            if ($("#zyryid").val() == null || $("#zyryid").val() == "") {
                layer.msg("人员不可为空");
            } else {
            zzpUtils.confirm("是否确定下发", function (index) {
                zzpUtils.action({
                    url: "/wmsinventoryplan/issuePlanRw",
                    data: JSON.stringify(data.field),
                    success: function (data) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            console.info(data);
                            top.layer.msg(data.title + "," + data.message);
                            //刷新父页面
                        }, 500);
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        }
            return false;

        });


        form.on('select(sheng)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            var sheng = $("#sheng").find("option:selected").attr("code");
            //判断省份这个下拉框选中的值是否为空
            if (sheng == "") {
                return;
            }
            $("#shi").html("");
            var str = "<option>==请选择===</option>";
            $.ajax({
                type: "GET",
                url: "/zxsswms/wmscityinfo/selectProvice/" + sheng,
                dataType: "JSON",
                async: false,
                success: function (data) {
                    //从服务器获取数据进行绑定
                    $.each(data, function (i, item) {
                        str += "<option value=" + item.cityname + ">" + item.cityname + "</option>";
                    })
                    console.info(str);
                    //将数据添加到省份这个下拉框里面
                    $("#shi").append(str);
                    console.info($("#shi").html());
                    form.render('select');
                },
                error: function () {
                    alert("Error");
                }
            });

        });
    });
</script>
</html>